Draw_Ship:



 di






;Find out what unit the player is using, and go to the proper instructions for handiling
;the unit

 ld a, (Player1 + Player_Unit)

 or a
 jr z, Draw_Scouter

 cp Raptor
 jr z, Draw_Raptor

 cp Tank
 jp z, Draw_Tank

 cp Degruser
 jp z, Draw_Degruser

 cp Reclauda
 jp z, Draw_Reclauda

 cp Camoza
 jp z, Draw_Camoza

 cp Splitron
 jp z, Draw_Splitron

 cp Balkstone
 jp z, Draw_Balkstone


Draw_Argo:
 BIT Load_Ship_Sprite, (IY + flag + 1)
 jr z, _
 B_CALL _Load_Argo
_
 jr Draw_Normal_Image

Draw_Raptor:
 BIT Load_Ship_Sprite, (IY + flag + 1)
 jr z, _
 B_CALL _Load_Raptor
_
 jr Draw_Normal_Image

Draw_Scouter:

 BIT Load_Ship_Sprite, (IY + flag + 1)
 jr z, _

 B_CALL _Load_Scouter

_
 jr Draw_Animation_Image

Draw_Tank:

Draw_Splitron:

 BIT Load_Ship_Sprite, (IY + flag + 1)
 jr z, _

 B_CALL _Load_Splitron
_

 jr Draw_Normal_Image

Draw_Balkstone:

 BIT Load_Ship_Sprite, (IY + flag + 1)
 jr z, _

 B_CALL _Load_Balkstone

_

 jr Draw_Normal_Image

Draw_Camoza:
 BIT Load_Ship_Sprite, (IY + flag + 1)
 jr z, _

 B_CALL _Load_Camoza
_
 jr Draw_Normal_Image

Draw_Degruser:
 BIT Load_Ship_Sprite, (IY + flag + 1)
 jr z, _

 B_CALL _Load_Degruser

_

 jr Draw_Normal_Image

Draw_Reclauda:

 BIT Load_Ship_Sprite, (IY + flag + 1)
 jr z, _
 B_CALL _Load_Reclauda
_
 jr Draw_Normal_Image



Draw_Normal_Image:


 ei


 RES Load_Ship_Sprite, (IY + flag + 1)

_

 call Draw_One_Frame_Image

 ret


Draw_Animation_Image:


	ei

	
	ld a, (Ship_Frame_Data + 4)

	rla

	add a, 5

	ld d, 0
	ld e, a

	ld a, (Player1 + Player_Animation)
	


	and %00000011
	call Multiply_DE_By_A

	ld de, Ship_Frame_Data
	add hl, de
	jr _
	
	



Draw_One_Frame_Image:

;Offsets the image so that the ship is drawn in the center of the screen


	ld hl, Ship_Frame_Data


_

	ld a, 47
	sub (hl)
	ld d, a		;D is the x coordinate for the sprite
	inc hl
 
	ld a, 31	;E is the y coordinate for the sprite
	sub (hl)
	ld e, a
	inc hl






	BIT Ship_Mode, (IY + flag + 2)
	jr nz, _
	

	push hl
	pop iy

	ld hl, (Player1 + Player_Map_X)

	
	ld de, (Map_X)
	sbc hl, de



	ld b, l	
	ld    de, 96
      	or a
	sbc    hl, de
    	add    hl, de
    	jr    c, EmergencyLocalLabel7

	ld d, 0
	ld a, (Ship_Frame_Data + 2)
	rla \ rla \ rla

	ld e, a

	add hl, de
	dec hl


	ret nc

EmergencyLocalLabel7:

	

	ld hl, (Player1 + Player_Map_Y)

	


	ld de, (Map_Y)
	or a
	sbc hl, de




	ld    de, 64
        ld c, l
	or a
	sbc    hl, de
    	add    hl, de
    	jr    c, EmergencyLocalLabel8
	ld d, 0
	ld a, (Ship_Frame_Data + 3)
	ld e, a
	add hl, de

	dec hl
    	ret nc



EmergencyLocalLabel8:


	ld e, c
	ld d, b


	jr ++_
_

	push hl

	ld hl, (Map_X)

	ld b, 0
	ld c, d




	add hl, bc
	ld (Player1 + Player_Map_X), hl


	ld hl, (Map_Y)

	ld b, 0
	ld c, e

	
	add hl, bc
	ld (Player1 + Player_Map_Y), hl
	pop hl
	jr ++_

_
	;C is the width of the sprite in bytes
	push iy
	pop hl
_	
	ld c, (hl)

	inc hl

	;B is the height of the sprite

	ld b, (hl)

	inc hl

	push de
	ld e, (hl)	;HL points to how far away the mask is
	inc hl
	ld d, 0

	push hl
	
	
	
	add hl, de

	push hl
	
	pop iy
	pop ix
	pop de

	;Draws the shadow of the vessel

	ld a, c
	ld (Sprite_Width), a
	ld a, e
	;add a, 7
	ld l, a
	ld a, d
	push ix
	push iy
	pop ix
	
	
	push bc
	push de
	push iy

	ld iy, flags
	SET Draw_Shadow, (IY + flag + 1)
	;call Put_Sprite_OR
	RES Draw_Shadow, (IY + flag + 1)

	pop iy
	pop de

;Saves this value for drawing the number of ships that
;a player is using at once.

	ld (Player_Ship_DE), de

	pop bc
	pop ix

	call LargeClippedSprite
	ld iy, flags

;Draws the number of ships that the player is using

	ld de, (Player_Ship_DE)

	BIT Ship_Mode, (IY + flag + 2)
	jr z, _

	

;DE now contains the Screen X / Y Position

	ld d, 31
	ld a, e
	sub 6
	ld e, a

	ld b, 5
	ld c, 4
	ld ix, Number_Of_Ships_Sprite
	ld iy, Number_Of_Ships_Sprite + 20

	call LargeClippedSprite
	jr ++_

_


;The X position of the box is the middle of the sprite
;minus 16.  The Y position is the Sprite Map_Y minus 6.




	ld hl, Ship_Frame_Data + 1

;C contains the X offset so that we can get to the middle of
;the ship sprite.


	ld c, (hl)
	



	ld a, d
	add a, c
	sub 16
	ld d, a

	ld a, e
	sub 6
	ld e, a


	ld b, 5
	ld c, 4
	ld ix, Number_Of_Ships_Sprite
	ld iy, Number_Of_Ships_Sprite + 20


	call LargeClippedSprite

_
	ld iy, flags
	ret	
 	

Play_Ship_Animation:


	ld a,$FF
	out (1),a

	ld a,$FE
	out (1),a
	nop
	nop

	in a, (1)

	;Don't animate if not moving

	and %00001111
	cp 15
	ret z
	
	ld a, (Player1 + Player_Animation)
	add a, 16
	ld b, a		;Saves the value

	and %11110000
	ld hl, Player1 + Player_Animation_Time 
	cp (hl)
	ld a, b
	jr nz, ++_
	

	and %00001100	;Gets the number of frames
			;in the animation


	srl a \ srl a
	ld c, a

	ld a, b
	and %00000011

	;If the animation is at its maximum frame

	cp c

	ld a, b
	
	jr nz, _

	and %11111100
	jr ++_
_
	

	inc a

_	
	

	ld (Player1 + Player_Animation), a
	

	ret


Move_Ship_At_Speed:

	ld a, (Player1 + Player_Speed)

	rrca \ rrca
	ld (Player1 + Player_Speed), a
	and %00000011
	ld d, 0
	ld e, a
	ld (delta), de
	ret